package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ResetDao {


	private String classname = "org.sqlite.JDBC";
	private String datei ="MittelstufenProjekt.db3";
	private String connectionstring = "jdbc:sqlite::resource:"+datei;


	public ResetDao () throws ClassNotFoundException{
		Class.forName(classname);
	}


	//resete die album table
	public void resetAlbum()throws SQLException{
		
		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from Album";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	//reste die Interpret table
	public void resetInterpret()throws SQLException{

		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from Interpret";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	//reset die lieder album
	public void resetLieder()throws SQLException{

		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from Lieder";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	//reste die sqlite_sequence
	public void resetSeqMusik()throws SQLException{

		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from sqlite_sequence where name ='Lieder' or name ='Album' or name ='Interpret'";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	//reset die playlist table
	public void resetSeqPlaylist()throws SQLException{

		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from sqlite_sequence where name ='Playlist'";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	// reste die table playlist
	public void resetPlaylist()throws SQLException{

		PreparedStatement statement = null;
		Connection conn = null;
		try{

			conn =  DriverManager.getConnection(connectionstring);
			String sql = "delete from playlist";
			statement = conn.prepareStatement(sql);
			statement.executeUpdate();

		}catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				statement.close();
				conn.close();
			}catch (SQLException e) {
			}

		}
	}
	
	
}
